package com.atde._05_behavioral_design_patterns.memento.game;


/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._05_behavioral_design_patterns.memento.game
 * @Author: Del
 * @CreateTime: 2025-06-30  02:46
 * @Description: 备忘录模式应用保存角色状态 --- 游戏角色类
 * @Version: 1.0
 */
public class GameRole {

    // 攻击力
    private int vit;
    // 防御力
    private int def;

    public GameRole() {
        // 默认角色状态
        vit = 100;
        def = 100;
    }

    public int getVit() {
        return vit;
    }

    public void setVit(int vit) {
        this.vit = vit;
    }

    public int getDef() {
        return def;
    }

    public void setDef(int def) {
        this.def = def;
    }

    // 创建Memento，即根据当前的状态得到Memento
    public Memento createMemento() {
        return new Memento(vit, def);
    }

    // 恢复Memento，即根据Memento恢复状态
    public void recoverMemento(Memento memento) {
        this.vit = memento.getVit();
        this.def = memento.getDef();
    }

    // 显示当前角色的状态
    public void show() {
        System.out.println("角色攻击力：" + vit + "，角色防御力：" + def);
    }
}
